package com.hmall.cart.listener;


import com.hmall.cart.service.ICartService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
@RequiredArgsConstructor
public class ClearCartListener {
    private final ICartService cartService;
    @RabbitListener(bindings =@QueueBinding(
            value =@Queue(name = "cart.clear.queue", durable = "true"),
            exchange =@Exchange(name = "trade.topic",type ="topic"),
            key = {"order.create"},
            arguments = @Argument(name = "x-queue-mode", value = "lazy")
    ))
    public void clearCart(Collection<Long> itemIds){
        cartService.removeByItemIds(itemIds);
    }
}
